package cn.lopr.im.android.utils.jwt;

import android.util.Base64;

import com.google.gson.Gson;

import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;

import cn.lopr.im.android.bean.User;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;

/**
 * @author shuangyang7
 * @date 2021/5/14 11:23
 */
public class JwtUtil {


    public static User getTokenInfo(String token) {
        String encode = Base64.encodeToString("cn.lopr.im.api".getBytes(), 0);
        SecretKey key = new SecretKeySpec("cn.lopr.im.api".getBytes(), "AES");
        Claims claims = Jwts.parser().setSigningKey(encode).parseClaimsJws(token).getBody();

        Object other = claims.get("other");
        String jsonStr = new Gson().toJson(other);
        User user = new Gson().fromJson(jsonStr, User.class);
        return user;
    }
}
